<?php
	define("MEMCACHE_SERVER", "localhost");
	define("MEMCACHE_PORT", "11211");
	
	class myMemcache{
		private $memcache;
		//private $db_cache;
		
		function __construct(){
			$memcache = new Memcache();
			if (@$memcache->connect(MEMCACHE_SERVER, MEMCACHE_PORT)){
				$this->memcache = $memcache;
			}
		//	$this->db_cache = new m_cache();
		}
		
		function getState(){
			return $this->memcache != null;
		}
		
		function add($key, $value){
			if ($this->getState()){
				return $this->memcache->add($key, $value);
			}
			//$this->db_cache->id = $key;
			//$this->db_cache->value = serialize($value);
			//return $this->db_cache->insert();
			return false;
		}	
		
		function set($key, $value){
			if ($this->getState()){
				return $this->memcache->set($key, $value);
			}
			//$this->db_cache->id = $key;
			//$this->db_cache->value = serialize($value);
			//return $this->db_cache->insertUpdate();
			return false;
		}	
		
		function get($key){
			if ($this->getState()){
				return $this->memcache->get($key);
			}
			//$this->db_cache->select("", array("id" => $key), 1);
			//return unserialize($this->db_cache->value);
			return false;
		}	
		
		function delete($key){
			if ($this->getState()){
				return $this->memcache->delete($key);
			}
			//$this->db_cache->id = $key;
			//return $this->db_cache->delete();
			return false;
		}	
		
		function increment($key){
			if ($this->getState()){
				return $this->memcache->increment($key);
			}
			//if ($this->db_cache->select("", array("id" => $key), 1)){
			//	$this->db_cache->value = serialize(unserialize($this->db_cache->value) + 1);
			//	return $this->db_cache->insertUpdate();
			//} else {
			//	return false;
			//}
			return false;
 		}	
		
		function decrement($key){
			if ($this->getState()){
				return $this->memcache->decrement($key);
			}
			//if ($this->db_cache->select("", array("id" => $key), 1)){
			//	$this->db_cache->value = serialize(unserialize($this->db_cache->value) - 1);
			//	return $this->db_cache->insertUpdate();
			//} else {
			//	return false;
			//}
			return false;
		}	
		
		function flush(){
			if ($this->getState()){
				return $this->memcache->flush();
			}
			//$sql = "TRUNCATE TABLE `".$this->db_cache->get_table_name()."`";
			//return $this->db_cache->query($sql);
			return false;
		}	
		
		function getStats(){
			if ($this->getState()){
				return $this->memcache->getStats();
			}
			//$result["using database"] = true;
			//return $result;
			return false;
		}
	}
?>